Skip to content

Bugfix: Don't record SRTM for table-less writes - #194

Open
ErikBrendel wants to merge 1 commit into
Automattic:trunkfrom
ErikBrendel:fix/srtm-tableless-writes
Open

ErikBrendel wants to merge 1 commit into
Automattic:trunkfrom
ErikBrendel:fix/srtm-tableless-writes

Conversation

@ErikBrendel

@ErikBrendel ErikBrendel commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #77.

A write without a detectable table (SET …) stores srtm[false], i.e. srtm[0]. The join detection then runs stripos( $query, 0 ), which PHP 8 reads as "0", so every later query containing a 0 (LIMIT 10, wp_10_posts) goes to the master. Now SRTM is only recorded when a table was found.

Repro (PHP 8.2):

$wpdb->query( 'SET SESSION wait_timeout = 600' );
$wpdb->get_var( 'SELECT ID FROM wp_posts LIMIT 10' ); // trunk: global__w, this branch: global__r

A write whose table get_table_from_query() cannot determine (SET,
START TRANSACTION without an IN_TABLE hint) stored srtm[false], which
PHP turns into srtm[0]. The join detection then calls stripos() with
the needle 0, which PHP 8 casts to "0", so every later query containing
a 0 (LIMIT 10, wp_10_posts, INTERVAL 30 DAY) was sent to the master for
the rest of the request. On PHP 7.3 to 7.4 the same call raised the
deprecation notice reported in Automattic#77.

Fixes Automattic#77
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db.php deprecated use of function

1 participant